package com.touni.designpattern.interpreterpattern;

import com.touni.designpattern.interpreterpattern.expression.AndExpression;
import com.touni.designpattern.interpreterpattern.expression.OrExpression;
import com.touni.designpattern.interpreterpattern.expression.TerminalExpression;

/**
 * @ClassName : InterpreterDemo
 * @Description :
 * @Author : lwq
 * @Date: 2020-11-21 10:16
 */
public class InterpreterDemo {

    public static void main(String[] args) {
        TerminalExpression andOne = new TerminalExpression("man");
        TerminalExpression andTwo = new TerminalExpression("mike");
        AndExpression andExpression = new AndExpression(andOne,andTwo);
        String matchText = "mike is a man";
        boolean mikeIsAMan = andExpression.interpreter(matchText);
        System.out.println(matchText + " " + mikeIsAMan);

        TerminalExpression orOne = new TerminalExpression("boy");
        TerminalExpression orTwo = new TerminalExpression("girl");
        OrExpression orExpression = new OrExpression(orOne,orTwo);
        boolean orResult = orExpression.interpreter(matchText);
        System.out.println(matchText + " " + orResult);
    }

}
